<?php

namespace App\Console\Commands;

use App\Services\Warehouse\Interfaces\ERPUserServiceInterface;
use App\Services\Warehouse\Services\ERPUserService;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Auth;

class ERPUserLoginCommand extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'user:login {uid}';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'ERP user login.';

    /**
     * @var ERPUserService
     */
    protected $ERPUserService;

    protected $guard = 'apiv2';


    public function __construct(ERPUserServiceInterface $ERPUserService)
    {
        parent::__construct();
        $this->ERPUserService = $ERPUserService;
    }

    /**
     * TODO 用uid查找erp用户，把这个用户作登录，返回token
     * @throws \Throwable
     */
    public function handle()
    {
        $uid = $this->argument('uid');
        if ($designer = $this->ERPUserService->find($uid)) {
            $token = Auth::guard($this->guard)->tokenById($designer['uid']);
            echo($token);
        }
        return;
    }
}
